package com.spzx.product.controller;

import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.core.web.page.TableDataInfo;
import com.spzx.common.log.annotation.Log;
import com.spzx.common.security.annotation.PrintLog;
import com.spzx.common.security.annotation.RequiresPermissions;
import com.spzx.common.security.utils.SecurityUtils;
import com.spzx.product.domain.Brand;
import com.spzx.product.service.BrandService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.apache.ibatis.annotations.Param;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.spzx.common.core.utils.PageUtils.startPage;


@RestController
@RequestMapping("/brand")
@Tag(name = "品牌管理模块")
public class BrandController extends BaseController {
    @Resource
    BrandService brandService;


    @Operation(summary = "根据三级id查询商品列表")
    @RequiresPermissions(value = {"product:brand:list"})
    @GetMapping("/list/{c3id}")
    public AjaxResult listByC3id(@PathVariable Long c3id){


        return success(brandService.selectBrandListByC3id(c3id));
    }


    @Operation(summary = "查询商品列表")
    @RequiresPermissions(value = {"product:brand:list"})
    @GetMapping
    public AjaxResult listAllBrand(){
        List<Brand> brandList = brandService.selectBrandList(null);
        return success(brandList);
    }

    @Operation(summary = "分页查询商品列表")
    @RequiresPermissions(value = {"product:brand:list"})
    /*@PrintLog(module = "分页查询商品列表")*/
    @Log(title = "查询品牌分页")
    @GetMapping("/list")
    public TableDataInfo list(Brand Brand){
        startPage();
           List<Brand> BrandList=  brandService.selectBrandList(Brand);

           return getDataTable(BrandList);
    }

    /**
     * 获取商品详细信息
     */
    @Operation(summary = "获取商品详细信息")
    @RequiresPermissions(value = {"product:brand:query"})
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        Brand Brand = brandService.selectBrandById(id);

        return success(Brand);
    }

  /*
    @Operation(summary = "获取商品详细信息列表")
    @GetMapping(value = "/idlist")
    public AjaxResult getInfo1(@RequestParam("ids") List<Long> ids)
    {
        List<Brand> Brand = brandService.selectBrandByIds(ids);

        return success(Brand);
    }*/


    /**
     * 添加内容
     */
    @Operation(summary = "新增商品")
    @RequiresPermissions(value = {"product:brand:add"})
    @PostMapping
    public AjaxResult add(@RequestBody @Validated Brand Brand){
           // Brand.setCreateBy(SecurityUtils.getUsername());
        return toAjax(brandService.insertBrand(Brand));
    }
    @Operation(summary = "修改商品")
    @RequiresPermissions(value = {"product:brand:edit"})
    @PutMapping
    public AjaxResult edit(@RequestBody @Validated Brand Brand){

        return toAjax(brandService.updateBrand(Brand));
    }
    @Operation(summary = "删除商品")
    @RequiresPermissions(value = {"product:brand:remove"})
    @DeleteMapping("{ids}")
    public AjaxResult remove(@PathVariable Long[] ids){
        return toAjax(brandService.deleteBrandByIds(ids));
    }

    @Operation(summary = "获取全部商品")
    @GetMapping("getBrandAll")
    public AjaxResult getBrandAll(){
        return success(brandService.selectBrandAll());
    }
}
